/*
 * Copyright (c) 2020-2021, SERI Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-05-22     Lyons        first version
 */

module pa_fpu_xfrac_adjust (
    xfrac_i,
    xfrac_o,
    expn_adjust_o
    );

//width of xfrac is 53-bits
//include: hidden:1 + frac:52, for single adden 0s at tail

input                           xfrac_i;
output                          xfrac_o;
output                          expn_adjust_o;

wire [52:0]                     xfrac_i;
wire [52:0]                     xfrac_o;
wire [11:0]                     expn_adjust_o;


reg  [52:0]                     xfrac_out;
reg  [11:0]                     expn_adjust_out;

wire [52:0]                     shift_pre_data;


assign shift_pre_data[52:0] = xfrac_i[52:0];

always @ (shift_pre_data[52:0]) begin
case (shift_pre_data[52:0])
    53'b1????_????????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[52:0]};
        expn_adjust_out[11:0] = 12'd0;
    end
    53'b01???_????????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[51:0], 1'b0};
        expn_adjust_out[11:0] = 12'd1;
    end
    53'b001??_????????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[50:0], 2'b0};
        expn_adjust_out[11:0] = 12'd2;
    end
    53'b0001?_????????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[49:0], 3'b0};
        expn_adjust_out[11:0] = 12'd3;
    end
    53'b00001_????????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[48:0], 4'b0};
        expn_adjust_out[11:0] = 12'd4;
    end
    53'b00000_1???????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[47:0], 5'b0};
        expn_adjust_out[11:0] = 12'd5;
    end
    53'b00000_01??????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[46:0], 6'b0};
        expn_adjust_out[11:0] = 12'd6;
    end
    53'b00000_001?????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[45:0], 7'b0};
        expn_adjust_out[11:0] = 12'd7;
    end
    53'b00000_0001????_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[44:0], 8'b0};
        expn_adjust_out[11:0] = 12'd8;
    end
    53'b00000_00001???_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[43:0], 9'b0};
        expn_adjust_out[11:0] = 12'd9;
    end
    53'b00000_000001??_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[42:0], 10'b0};
        expn_adjust_out[11:0] = 12'd10;
    end
    53'b00000_0000001?_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[41:0], 11'b0};
        expn_adjust_out[11:0] = 12'd11;
    end
    53'b00000_00000001_????????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[40:0], 12'b0};
        expn_adjust_out[11:0] = 12'd12;
    end
    53'b00000_00000000_1???????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[39:0], 13'b0};
        expn_adjust_out[11:0] = 12'd13;
    end
    53'b00000_00000000_01??????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[38:0], 14'b0};
        expn_adjust_out[11:0] = 12'd14;
    end
    53'b00000_00000000_001?????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[37:0], 15'b0};
        expn_adjust_out[11:0] = 12'd15;
    end
    53'b00000_00000000_0001????_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[36:0], 16'b0};
        expn_adjust_out[11:0] = 12'd16;
    end
    53'b00000_00000000_00001???_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[35:0], 17'b0};
        expn_adjust_out[11:0] = 12'd17;
    end
    53'b00000_00000000_000001??_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[34:0], 18'b0};
        expn_adjust_out[11:0] = 12'd18;
    end
    53'b00000_00000000_0000001?_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[33:0], 19'b0};
        expn_adjust_out[11:0] = 12'd19;
    end
    53'b00000_00000000_00000001_????????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[32:0], 20'b0};
        expn_adjust_out[11:0] = 12'd20;
    end
    53'b00000_00000000_00000000_1???????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[31:0], 21'b0};
        expn_adjust_out[11:0] = 12'd21;
    end
    53'b00000_00000000_00000000_01??????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[30:0], 22'b0};
        expn_adjust_out[11:0] = 12'd22;
    end
    53'b00000_00000000_00000000_001?????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[29:0], 23'b0};
        expn_adjust_out[11:0] = 12'd23;
    end
    53'b00000_00000000_00000000_0001????_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[28:0], 24'b0};
        expn_adjust_out[11:0] = 12'd24;
    end
    53'b00000_00000000_00000000_00001???_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[27:0], 25'b0};
        expn_adjust_out[11:0] = 12'd25;
    end
    53'b00000_00000000_00000000_000001??_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[26:0], 26'b0};
        expn_adjust_out[11:0] = 12'd26;
    end
    53'b00000_00000000_00000000_0000001?_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[25:0], 27'b0};
        expn_adjust_out[11:0] = 12'd27;
    end
    53'b00000_00000000_00000000_00000001_????????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[24:0], 28'b0};
        expn_adjust_out[11:0] = 12'd28;
    end
    53'b00000_00000000_00000000_00000000_1???????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[23:0], 29'b0};
        expn_adjust_out[11:0] = 12'd29;
    end
    53'b00000_00000000_00000000_00000000_01??????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[22:0], 30'b0};
        expn_adjust_out[11:0] = 12'd30;
    end
    53'b00000_00000000_00000000_00000000_001?????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[21:0], 31'b0};
        expn_adjust_out[11:0] = 12'd31;
    end
    53'b00000_00000000_00000000_00000000_0001????_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[20:0], 32'b0};
        expn_adjust_out[11:0] = 12'd32;
    end
    53'b00000_00000000_00000000_00000000_00001???_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[19:0], 33'b0};
        expn_adjust_out[11:0] = 12'd33;
    end
    53'b00000_00000000_00000000_00000000_000001??_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[18:0], 34'b0};
        expn_adjust_out[11:0] = 12'd34;
    end
    53'b00000_00000000_00000000_00000000_0000001?_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[17:0], 35'b0};
        expn_adjust_out[11:0] = 12'd35;
    end
    53'b00000_00000000_00000000_00000000_00000001_????????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[16:0], 36'b0};
        expn_adjust_out[11:0] = 12'd36;
    end
    53'b00000_00000000_00000000_00000000_00000000_1???????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[15:0], 37'b0};
        expn_adjust_out[11:0] = 12'd37;
    end
    53'b00000_00000000_00000000_00000000_00000000_01??????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[14:0], 38'b0};
        expn_adjust_out[11:0] = 12'd38;
    end
    53'b00000_00000000_00000000_00000000_00000000_001?????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[13:0], 39'b0};
        expn_adjust_out[11:0] = 12'd39;
    end
    53'b00000_00000000_00000000_00000000_00000000_0001????_????????: begin
        xfrac_out[52:0] = {shift_pre_data[12:0], 40'b0};
        expn_adjust_out[11:0] = 12'd40;
    end
    53'b00000_00000000_00000000_00000000_00000000_00001???_????????: begin
        xfrac_out[52:0] = {shift_pre_data[11:0], 41'b0};
        expn_adjust_out[11:0] = 12'd41;
    end
    53'b00000_00000000_00000000_00000000_00000000_000001??_????????: begin
        xfrac_out[52:0] = {shift_pre_data[10:0], 42'b0};
        expn_adjust_out[11:0] = 12'd42;
    end
    53'b00000_00000000_00000000_00000000_00000000_0000001?_????????: begin
        xfrac_out[52:0] = {shift_pre_data[9:0],  43'b0};
        expn_adjust_out[11:0] = 12'd43;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000001_????????: begin
        xfrac_out[52:0] = {shift_pre_data[8:0],  44'b0};
        expn_adjust_out[11:0] = 12'd44;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_1???????: begin
        xfrac_out[52:0] = {shift_pre_data[7:0],  45'b0};
        expn_adjust_out[11:0] = 12'd45;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_01??????: begin
        xfrac_out[52:0] = {shift_pre_data[6:0],  46'b0};
        expn_adjust_out[11:0] = 12'd46;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_001?????: begin
        xfrac_out[52:0] = {shift_pre_data[5:0],  47'b0};
        expn_adjust_out[11:0] = 12'd47;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_0001????: begin
        xfrac_out[52:0] = {shift_pre_data[4:0],  48'b0};
        expn_adjust_out[11:0] = 12'd48;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_00001???: begin
        xfrac_out[52:0] = {shift_pre_data[3:0],  49'b0};
        expn_adjust_out[11:0] = 12'd49;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_000001??: begin
        xfrac_out[52:0] = {shift_pre_data[2:0],  50'b0};
        expn_adjust_out[11:0] = 12'd50;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_0000001?: begin
        xfrac_out[52:0] = {shift_pre_data[1:0],  51'b0};
        expn_adjust_out[11:0] = 12'd51;
    end
    53'b00000_00000000_00000000_00000000_00000000_00000000_00000001: begin
        xfrac_out[52:0] = {shift_pre_data[0],    52'b0};
        expn_adjust_out[11:0] = 12'd52;
    end
    default : begin
        xfrac_out[52:0] = 53'b0;
        expn_adjust_out[11:0] = 12'd52;
    end
endcase
end

assign xfrac_o[52:0] = xfrac_out[52:0];

assign expn_adjust_o[11:0] = expn_adjust_out[11:0];

endmodule